package com.example.springdemo5;

import com.aop.AspectJConfig;
import com.aop.UserDao;
import com.aop.UserDaoByAno;
import com.bean.AnoConfig;
import com.bean.Customer;
import com.bean.CustomerByAnotation;
import com.bean.CustomerConstructor;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@SpringBootApplication
public class Springdemo5Application {

    public static void main(String[] args) {
        SpringApplication.run(Springdemo5Application.class, args);

        ApplicationContext context =new ClassPathXmlApplicationContext("appConfig.xml");
//        Customer customer = (Customer) context.getBean("cu");
//        System.out.println("这是通过setter注入的方式实现的bean装载，id=" + customer.getId()
//        +"uname = " + customer.getUname() + "password=" + customer.getPassword());
//
//
//        System.out.println("***********************************");
//        System.out.println("以下是通过构造器装载的bean对象");
//        CustomerConstructor cu2 = (CustomerConstructor) context.getBean("cu2");
//        System.out.println("id=" + cu2.getId()
//                +" uname = " + cu2.getUname() + " password=" + cu2.getPassword());
//
//        System.out.println("****以下是通过注解方式装载Bean对象****");
//        ApplicationContext con1 = new AnnotationConfigApplicationContext(AnoConfig.class);
//        CustomerByAnotation cuAno = con1.getBean(CustomerByAnotation.class);
//        System.out.println("id=" + cuAno.getId()
//                +" uname = " + cuAno.getUname() + " password=" + cuAno.getPassword());
//        //这是AspectJ目标方法的调用
//        UserDao userDao = (UserDao) context.getBean("userImpl");
//        userDao.addUser();
//        userDao.delUser();

        //以下是基于注解方式实现的AspectJ
        ApplicationContext con2 = new AnnotationConfigApplicationContext(AspectJConfig.class);
        UserDaoByAno userDaoByAno = con2.getBean(UserDaoByAno.class);
        userDaoByAno.addUser();
    }

    @GetMapping("/helloClass5")
    public String hello() {
        return "spring project by class5";
    }

}
